package com.lwj.test.netty;

import java.net.InetSocketAddress;
import java.util.concurrent.Executors;
import org.jboss.netty.bootstrap.ServerBootstrap;
import org.jboss.netty.channel.socket.nio.NioServerSocketChannelFactory;

public class NettyServer {

	private static NettyServer server = new NettyServer();

	private ServerBootstrap bootstrap;

	private NettyServer() {
	}

	public static NettyServer getInstance() {
		return server;
	}

	public void start() {
		bootstrap = new ServerBootstrap(new NioServerSocketChannelFactory(
				Executors.newCachedThreadPool(),
				Executors.newCachedThreadPool()));
		bootstrap.setPipelineFactory(new ServerPipelineFactory());
		InetSocketAddress isa = new InetSocketAddress("192.168.5.124",8980);
		bootstrap.bind(isa);
		System.out.println(isa.getAddress()+"---"+isa.getHostName()+"  ");
	}

	public void stop() {
		bootstrap.releaseExternalResources();
	}

	public static void main(String[] args) {
		NettyServer server = NettyServer.getInstance();
		server.start();
		
	}
}
